package com.lanou.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lanou.pojo.PaymentDepositEntity;
import com.lanou.pojo.PaymentMethod;
import com.lanou.service.depositService;
import com.lanou.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@Api(value = "押金管理",tags = "押金")
public class DepositController {
    @Resource
    private depositService depositService;
    @ApiOperation(value = "押金管理获取请求列表",httpMethod = "GET")
    @RequestMapping(value = "/depositList",produces ="text/html;charset=utf-8")
    public String depositList(String pageNum , String pageSize, String resourceName, String feeUser, String state, String feeItemName, String payType){
        //        处理分页查询
        if(pageNum == null || "".equals(pageNum)){
            pageNum="1";
        }
        if(pageSize == null || "".equals(pageSize)){
            pageSize="5";
        }

        PageHelper.startPage(Integer.valueOf(pageNum),Integer.valueOf(pageSize));
        List<PaymentDepositEntity> paymentDepositList = depositService.paymentDepositList(pageNum, pageSize, resourceName, feeUser, state, feeItemName, payType);


        PageInfo info = new PageInfo<>(paymentDepositList);
        JsonResult jsonResult = new JsonResult<>();
        jsonResult.setStatus(200);
        jsonResult.setData(info);

        return JSON.toJSONString(jsonResult);
    }
    @ApiOperation(value = "押金管理添加数据",httpMethod = "POST")
    @RequestMapping("/addPaymentDeposit")
    public void addPaymentDeposit( @RequestBody Map<String,String> requestbody) throws ParseException {
        String id = requestbody.get("id");
        String name = requestbody.get("name");
        String chargeitem = requestbody.get("chargeitem");
        String paymethod = requestbody.get("paymethod");
        String money = requestbody.get("money");
        String date1 = requestbody.get("date1");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = dateFormat.parse(date1);
        System.out.println(requestbody);
        depositService.addPaymentDeposit(id,name,chargeitem,paymethod,money,date);


    }
    @ApiOperation(value = "押金管理更新数据",httpMethod = "POST")
    @RequestMapping("/updateByid")
    @ResponseBody
    public void updateByid(@RequestBody Map<String,String> requestbody) throws ParseException {
        String remark = requestbody.get("remark");
        String refundType = requestbody.get("refundType");
        String id = requestbody.get("id");
        String time = requestbody.get("refundTime");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date refundTime = dateFormat.parse(time);

        depositService.updateByid(refundTime,remark,refundType,id);
    }

    @ApiOperation(value = "押金管理获取支付方式列表",httpMethod = "GET")
    @RequestMapping(value = "/payment_method",produces ="text/html;charset=utf-8")
    public String PayMethods(){

        List<PaymentMethod> list = depositService.selectPayMethod();
        JsonResult jsonResult = new JsonResult<>();
        jsonResult.setStatus(200);
        jsonResult.setData(list);
        return JSON.toJSONString(jsonResult);

    }
    @ApiOperation(value = "押金管理列表",httpMethod = "GET")
    @RequestMapping("/paymentContract")
      public String selectpaymentContract(){
        List<String> list = depositService.selectpaymentContract();
        JsonResult jsonResult = new JsonResult<>();
        jsonResult.setStatus(200);
        jsonResult.setData(list);
        return JSON.toJSONString(jsonResult);
    }
    
}
